package test38;

import java.io.*;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-05-09
 * Time: 16:57
 */
//https://www.nowcoder.com/questionTerminal/5017fd2fc5c84f78bbaed4777996213a
// 就是深度遍历
    // 不是一趟最多走的瓷砖数
//public class Main {
//    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//    static int[] X = {-1, 1, 0, 0};
//    static int[] Y = {0, 0, -1, 1};
//
//    public static void main(String[] args) throws IOException {
//        String str = null;
//        while ((str = br.readLine()) != null) {
//            String[] strs = str.split(" ");
//            int row = Integer.parseInt(strs[0]);
//            int col = Integer.parseInt(strs[1]);
//            char[][] arr = new char[row][col];
//            for (int i = 0; i < row; i++) {
//                arr[i] = br.readLine().toCharArray();
//            }
//            //1. “.”：黑色的瓷砖；
//            //2. “#”：白色的瓷砖；
//            //3. “@”：黑色的瓷砖，并且你站在这块瓷砖上。该字符在每个数据集合中唯一出现一次。
//            int count = 0;
//            for (int i = 0; i < row; i++) {
//                for (int j = 0; j < col; j++) {
//                    if (arr[i][j] == '@') {
//                        arr[i][j] = '.';
//                        count = dfs(arr, i, j);
//                        break;
//                    }
//                }
//                if (count != 0) {
//                    break;
//                }
//            }
//            bw.write(count + "\n");
//        }
//        bw.flush();
//        bw.close();
//        br.close();
//    }
//
//    public static int dfs(char[][] arr, int x, int y) {
//        int row = arr.length;
//        int col = arr[0].length;
//        if (x < 0 || x >= row || y < 0 || y >= col || arr[x][y] != '.') {
//            return 0;
//        }
//        int count = 0;
//        arr[x][y] = '#';
//        count++;
//        for (int i = 0; i < 4; i++) {
//            int dx = x + X[i];
//            int dy = y + Y[i];
//            count += dfs(arr, dx, dy);
//        }
//        return count;
//    }
//}


public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    static int[] X = {-1, 1, 0, 0};
    static int[] Y = {0, 0, -1, 1};

    public static void main(String[] args) throws IOException {
        String str = null;
        while ((str = br.readLine()) != null) {
            String[] strs = str.split(" ");
            int row = Integer.parseInt(strs[0]);
            int col = Integer.parseInt(strs[1]);
            char[][] arr = new char[row][col];
            for (int i = 0; i < row; i++) {
                arr[i] = br.readLine().toCharArray();
            }
            //1. “.”：黑色的瓷砖；
            //2. “#”：白色的瓷砖；
            //3. “@”：黑色的瓷砖，并且你站在这块瓷砖上。该字符在每个数据集合中唯一出现一次。
            int count = 0;
            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {
                    if (arr[i][j] == '@') {
                        arr[i][j] = '.';
                        count = bfs(arr, i, j);
                        break;
                    }
                }
                if (count != 0) {
                    break;
                }
            }
            bw.write(count + "\n");
        }
        bw.flush();
        bw.close();
        br.close();
    }



    public static int bfs(char[][] arr, int x, int y) {
        int row = arr.length;
        int col = arr[0].length;
        Deque<int[]> queue = new LinkedList<>();
        int count = 1;
        arr[x][y] = '#';
        queue.offer(new int[]{x, y});
        while (!queue.isEmpty()) {
            int[] temp = queue.poll();
            int mx = temp[0];
            int my = temp[1];
            for (int i = 0; i < 4; i++) {
                int dx = mx + X[i];
                int dy = my + Y[i];
                if (dx < 0 || dx >= row || dy < 0 || dy >= col || arr[dx][dy] != '.') {
                    continue;
                }
                queue.offer(new int[]{dx, dy});
                arr[dx][dy] = '#';
                count++;
            }
        }
        return count;
    }
}